# -*- coding: utf-8 -*-
"""
@Time ： 2023/4/6 20:58
@Auth ： 叶东宇
@File ：长度最小子数组.py
"""

def min_lens(lis,s):
    """
    sorted
    reverse=false:默认升序
    """
    j = {}
    for i in range(len(lis)):
        for k in range(i, len(lis)):
            if sum(lis[i:k+1]) >= s:
                j[str(lis[i:k+1])] = k+1-i
    if len(j) == 0:
        return 0
    else:
        tmp = sorted(j.items(), key=lambda x: x[1], reverse=False)
        return tmp[0][0], tmp[0][1]

def slid_window(lis, s):
    start = 0
    end = 0
    l = []
    while start < len(lis):
        if end == start:
            start += 1
            continue
        if sum(lis[end:start+1])<s:
            start += 1
        else:
            l.append(start-end+1)
            end += 1
    return min(l)
if __name__ == "__main__":
    lis = [1,2,3,4,5,6,3,2,4,2,3,4,5,6,0]
    target = 8
    print(slid_window(lis,target))